package com.woniuxy.automotivemanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.automotivemanagementsystem.entity.Menu;
import com.woniuxy.automotivemanagementsystem.entity.Role;
import com.woniuxy.automotivemanagementsystem.entity.User;
import com.woniuxy.automotivemanagementsystem.mapper.MenuMapper;
import com.woniuxy.automotivemanagementsystem.mapper.RoleMapper;
import com.woniuxy.automotivemanagementsystem.service.MenuService;
import com.woniuxy.automotivemanagementsystem.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private MenuMapper menuMapper;
    @Override
    public List<Role> findRoleByUserId(Integer uid) {
        return roleMapper.findRoleByUserId(uid);
    }

    @Override
    public List<User> selectUserByRid(Integer rid) {
        return roleMapper.selectUserByRid(rid);
    }

    @Override
    @Transactional
    public void updateMenusByRoleId(Integer rid, List<Menu> menus) {
        menuMapper.removeByRid( rid);
        for (Menu menu : menus){
            menuMapper.add(rid,menu.getMid());
        }
    }
}
